package com.starlink.controller.admin;

import com.github.pagehelper.PageInfo;
import com.starlink.client.jd.vo.PrintPullDataVO;
import com.starlink.common.WebResponse;
import com.starlink.common.annotation.WebAccess;
import com.starlink.model.request.SchoolbagOrderRequest;
import com.starlink.model.request.SchoolbagOrderJdRequest;
import com.starlink.model.request.SchoolbagRecoveryCheckRequest;
import com.starlink.model.request.SchoolbagRecoveryRequest;
import com.starlink.model.vo.SchoolbagOrderVO;
import com.starlink.model.vo.SchoolbagRecoveryCheckVO;
import com.starlink.model.vo.SchoolbagRecoveryVO;
import com.starlink.service.SchoolbagOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.SortDefault;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author zhanghong
 */
@RestController
@RequestMapping("/admin/schoolBagOrder")
@Api(value = "【管理端】书包订单模块", tags = {"【管理端】书包订单模块"})
public class AdminSchoolbagOrderController {

    @Autowired
    private SchoolbagOrderService schoolbagOrderService;

    @WebAccess(login = true)
    @ApiOperation(value = "根据主键查询", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/get/{id}")
    public WebResponse<SchoolbagOrderVO> getByKey(HttpServletRequest request, @PathVariable("id") long id) {
        return WebResponse.build(schoolbagOrderService.getByKey(id));
    }

    @WebAccess(login = true)
    @ApiOperation("分页查询")
    @PostMapping("/pageQuery")
    public WebResponse<PageInfo<SchoolbagOrderVO>> pageQuery(@SortDefault(sort = {"create_time"}, direction = Sort.Direction.DESC) Pageable pageable, @RequestBody SchoolbagOrderRequest request) {
        return WebResponse.build(schoolbagOrderService.pageQuery(pageable, request));
    }

    @WebAccess(login = true)
    @ApiOperation("列表查询")
    @PostMapping("/listQuery")
    public WebResponse<List<SchoolbagOrderVO>> listQuery(@RequestBody SchoolbagOrderRequest request) {
        return WebResponse.build(schoolbagOrderService.listQuery(request));
    }

//    @WebAccess(login = true)
//    @ApiOperation("新增")
//    @PostMapping("/add")
//    public WebResponse<Boolean> add(@Valid @RequestBody SchoolbagOrderRequest request) {
//        return WebResponse.build(schoolbagOrderService.add(request));
//    }
//
//    @WebAccess(login = true)
//    @ApiOperation("删除")
//    @PostMapping("/delete")
//    public WebResponse<Boolean> deleteByKey(@RequestParam("ids") String ids) {
//        return WebResponse.build(schoolbagOrderService.deleteDOByIds(ids));
//    }

    @WebAccess(login = true)
    @ApiOperation("下物流单(发货)")
    @PostMapping("/deliverySubmitJdOrder")
    public WebResponse<Boolean> deliverySubmitJdOrder(@RequestBody SchoolbagOrderJdRequest request) {
        return WebResponse.build(schoolbagOrderService.deliverySubmitJdOrder(request));
    }

    @WebAccess(login = true)
    @ApiOperation("下物流单(回收)")
    @PostMapping("/recoverySubmitJdOrder")
    public WebResponse<Boolean> recoverySubmitJdOrder(@RequestBody SchoolbagOrderJdRequest request) {
        return WebResponse.build(schoolbagOrderService.recoverySubmitJdOrder(request));
    }

    @WebAccess(login = true)
    @ApiOperation("打印物流单（获取打印数据）")
    @PostMapping("/getPrintData")
    public WebResponse<PrintPullDataVO> getPrintData(@RequestBody SchoolbagOrderJdRequest request) {
        return WebResponse.build(schoolbagOrderService.getPrintData(request));
    }

    @Deprecated
    @WebAccess(login = true)
    @ApiOperation("根据书包芯片码获取订单信息以及书包信息")
    @PostMapping("/getOrderInfoByRasId")
    public WebResponse<SchoolbagRecoveryVO> getOrderInfoByRasId(@RequestBody SchoolbagRecoveryRequest request) {
        return WebResponse.build(schoolbagOrderService.getOrderInfoByRasId(request));
    }

    @WebAccess(login = true)
    @ApiOperation("根据书包芯片码获取待发货-订单信息以及书包信息")
    @PostMapping("/getWaitDeliveryOrderInfoByRasId")
    public WebResponse<SchoolbagRecoveryVO> getWaitDeliveryOrderInfoByRasId(@RequestBody SchoolbagRecoveryRequest request) {
        return WebResponse.build(schoolbagOrderService.getWaitDeliveryOrderInfoByRasId(request));
    }

    @WebAccess(login = true)
    @ApiOperation("根据书包芯片码获取待收货-订单信息以及书包信息")
    @PostMapping("/getWaitCollectOrderInfoByRasId")
    public WebResponse<SchoolbagRecoveryVO> getWaitCollectOrderInfoByRasId(@RequestBody SchoolbagRecoveryRequest request) {
        return WebResponse.build(schoolbagOrderService.getWaitCollectOrderInfoByRasId(request));
    }

    @WebAccess(login = true)
    @ApiOperation("收货&核对")
    @PostMapping("/recoveryCheck")
    public WebResponse<SchoolbagRecoveryCheckVO> recoveryCheck(@RequestBody SchoolbagRecoveryCheckRequest request) {
        return WebResponse.build(schoolbagOrderService.recoveryCheck(request));
    }
}
